/**
 * 
 */
package com.block.common.security.util;


import com.alibaba.fastjson.JSONObject;
import com.block.common.security.service.factory.ReqDataTransferFactory;
import com.block.common.security.service.factory.ReturnDataFactory;
import com.block.common.service.LogFactory;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import org.slf4j.Logger;

import java.util.Date;


/**
 * 
 * APP通信接口工具
 */
public class ApiUtil {

	private static final Logger log = LogFactory.getAppReq();

	/**
	 * 返回json处理
	 * @param returnJson
	 * @param appEncrypt
	 * 2016年10月12日 下午5:06:44
	 */
	public static String dealReturnJson(ResponseVo returnJson, AppEncrypt appEncrypt, Date startDate, String actionName)
	{
		String returnMsg= ReturnDataFactory.getReturnDataService(appEncrypt.getEncryptType()).
			dealReturnData(appEncrypt, returnJson, startDate);

			log.info("时间:{},【URI】{}【返回的数据】{}",startDate,actionName,returnMsg);
			if (returnMsg.contains("mobile")){
				log.info("【URI】{} 【message】包含手机号",returnMsg);
			}

		return returnMsg;
	}

	/**
	 * 请求数据处理
	 * @param appEncrypt
	 * @param jsonObject
	 * @param methodName
	 * @return
	 * 2016年12月19日 下午7:06:00
	 */
	public static JSONObject dealReqData(AppEncrypt appEncrypt, JSONObject jsonObject, String methodName) throws Exception {
		return ReqDataTransferFactory.getReqDataTransferService(appEncrypt.getEncryptType())
			.transferReqData(appEncrypt, jsonObject, methodName);
	}
	
}

